﻿using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism.Commands;

namespace prismapp.ViewModels
{
    internal class ViewCModel : IDialogAware
    {
        //command命令
        public DelegateCommand CancelCommand { get; set; }
        public DelegateCommand SaveCommand { get; set; }

        //构造函数
        public ViewCModel()
        {
            CancelCommand = new DelegateCommand(Cancel);
            SaveCommand = new DelegateCommand(Save);
        }


        private void Save()
        {
            OnDialogClosed();
            
        }

        private void Cancel()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.No));
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            var keys = new DialogParameters { { "Value", "Hello,World" } };
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, keys));
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            // throw new NotImplementedException();
        }

        public string? Title { get; set; }
        public event Action<IDialogResult>? RequestClose;
    }
}